package itsecurity.ui;

import java.security.Security;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import iaik.security.provider.IAIK;
import itsecurity.cert.MDBProvider;
import itsecurity.collision.CollisionFinder;
import itsecurity.hash.DaviesMeyerDES;
import itsecurity.hash.roque.DaviesMeyerDESRoque;

/**
 * Calculates speed for hash function.
 * Result (24.6.): 50 sec for 2^20 hashes with 1,2 Ghz processor
 *
 */
public class SpeedTest {

	public static void main (String [] args) {
		
		try {
      Security.insertProviderAt(new IAIK(), 2);
      Security.insertProviderAt(new MDBProvider(), 3);
    } catch( Throwable e ) {
      //
    }
    byte[] iv = new byte[8];
   	byte[] m = new byte[8];
		CollisionFinder cf = new CollisionFinder();
		Date start = new Date();
		byte[] data = new byte[8];
		for (int i=0; i<Math.pow(2, 20); i++)
			try {
				cf.hash(iv, m);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		Date end = new Date();
		long ms = end.getTime()-start.getTime();
		System.out.println("Time elapsed: "+ 
				String.format("%d min, %d sec", 
		    TimeUnit.MILLISECONDS.toMinutes(ms),
		    TimeUnit.MILLISECONDS.toSeconds(ms) - 
		    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(ms))
				)
		);

	}
}
